package com.jl.card.parse.part;

import java.util.Iterator;

import opencard.opt.util.TLV;

import com.jl.card.JL;
import com.jl.card.parse.IAPDUComponent;
import com.jl.card.util.SimpleTLV;
import com.jl.util.HexUtil;

public class RDATAPart extends APDUPart{

	public RDATAPart(IAPDUComponent parent, byte[] part) {
		super(parent, part);
		analyse();
	}

	@Override
	public String getSummary() {
		return "RDATA:" + HexUtil.toHexCompact(part);
	}

	@Override
	public void analyse() {
		if(!(parent instanceof APDUComponentManager)){return;}
		byte ins = ((APDUComponentManager)parent).getIns();
		switch (ins) {
		case JL.INS_FETCH:
			TLV tlv = new TLV(part);
			new TLVPart(this, part);
			SimpleTLV stlv2 = new SimpleTLV(null, tlv.valueAsByteArray());
			analyseSimpleTLV(stlv2);
			break;
		default:
			break;
		}
	}
	
	private void analyseSimpleTLV(SimpleTLV tlv){
		Iterator<SimpleTLV> it = tlv.iterator();
		while(it.hasNext()){
			SimpleTLV temp = it.next();
			new SimpleTLVPart(this, temp.toBinary());
		}
	}

}
